public class Solution {
    public boolean canJump(int[] nums) {
        int len = nums.length;
        if (len == 1) {
            return true;
        }

        int end = 0;
        int maxEnd = nums[0];
        int count = 0;
        while (end < len) {
            count++;
            int num = 0;
            while (end < len && end <= maxEnd) {
                num = Math.max(num, end + nums[end]);
                end++;
            }
            if (num == 0) {
                return false;
            }
            maxEnd = num;
        }

        return true;
    }
}
